<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div id="content-outer">
	<!-- start content -->
	<div id="content">

		<!--  start page-heading -->
		<div id="page-heading">
			<h1>
				<a href="subjects">Subjects</a>
			</h1>
		</div>
		<!-- end page-heading -->

		<table border="0" width="100%" cellpadding="0" cellspacing="0"
			id="content-table">
			<tr>
				<th rowspan="3" class="sized"><img
					src="/resources/images/shared/side_shadowleft.jpg" width="20"
					height="300" alt="" /></th>
				<th class="topleft"></th>
				<td id="tbl-border-top">&nbsp;</td>
				<th class="topright"></th>
				<th rowspan="3" class="sized"><img
					src="/resources/images/shared/side_shadowright.jpg" width="20"
					height="300" alt="" /></th>
			</tr>
			<tr>
				<td id="tbl-border-left"></td>
				<td>
					<!--  start content-table-inner ...................................................................... START -->
					<div id="content-table-inner">

						<!--  start table-content  -->
						<div id="table-content">
							<ul>
								<c:if test="${empty subjects}">
									No subject found !
								</c:if>
								<c:if test="${not empty subjects }">
									<c:forEach var="item" items="${subjects }">
										<li><a href="subject?id=${item.id}">${item.name} </a></li>
									</c:forEach>
								</c:if>
							</ul>
						</div>
						<!--  end table-content  -->

						<div class="clear"></div>

					</div> <!--  end content-table-inner ............................................END  -->
				</td>
				<td id="tbl-border-right"></td>
			</tr>
			<tr>
				<th class="sized bottomleft"></th>
				<td id="tbl-border-bottom">&nbsp;</td>
				<th class="sized bottomright"></th>
			</tr>
		</table>
		<script type="text/javascript">
			function onClickAddSubject(){
				var newURL = "";
	            var questionMarkLocation = document.URL.indexOf("?");
	            if (questionMarkLocation != -1) {
	                newURL = document.URL.substring(0, questionMarkLocation); 
	            } else {
	                newURL = document.URL;
	            }
	            
	            newURL = getBaseURL() + "add-subject" ;
	            
	            document.location=newURL;
			}
			
			function getBaseURL() {
			    var url = location.href;  // entire url including querystring - also: window.location.href;
			    var baseURL = url.substring(0, url.indexOf('/', 14));


			    if (baseURL.indexOf('http://localhost') != -1) {
			        // Base Url for localhost
			        var url = location.href;  // window.location.href;
			        var pathname = location.pathname;  // window.location.pathname;
			        var index1 = url.indexOf(pathname);
			        var index2 = url.indexOf("/", index1 + 1);
			        var baseLocalUrl = url.substr(0, index2);

			        return baseLocalUrl + "/";
			    }
			    else {
			        // Root Url for domain name
			        return baseURL + "/";
			    }

			}
		</script>
		<button id="add-subject-btn" type="button" onclick="javascript:onClickAddSubject();">Add subject</button>
		
		<div class="">&nbsp;</div>

	</div>
	<!--  end content -->
	<div class="clear">&nbsp;</div>
</div>